package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class JDBCDemo10 {
    public static void main(String[] args) {
        try (Connection conn=DBUtil.getConnection()){
            Scanner sc=new Scanner(System.in);
            PreparedStatement ps=conn.prepareStatement("update user set password = ? " +
                    ",nickname = ? ,age=? where username=?");
            System.out.println("请输入要修改的用户名");
            String username=sc.nextLine();
            ps.setString(4,username);
            System.out.println("请输入要修改的密码");
            ps.setString(1,sc.nextLine());
            System.out.println("请输入要修改的昵称");
            ps.setString(2,sc.nextLine());
            System.out.println("请输入要修改的年龄");
            ps.setInt(3,Integer.parseInt(sc.nextLine()));

            int num = ps.executeUpdate();
            if(num>0){
                System.out.println("修改成功");
            }else{
                System.out.println("修改失败");
            }

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
